<template>
  <div id="style22" class="app-container">
      <h2>宠物体检信息添加</h2>
       <el-form label-width="120px">
         <el-form-item label="宠物类型">
             <el-col :span="8">
            <el-input :disabled="true" v-model="petInformation.petType"/>
             </el-col>
         </el-form-item>

         <el-form-item label="体温">
             <el-col :span="8">
            <el-input v-model="petInformation.temperature"/>
             </el-col>38~39C
         </el-form-item>

         <el-form-item label="体重">
             <el-col :span="8">
            <el-input v-model="petInformation.weight"/>
             </el-col>7~10斤
         </el-form-item>

         <el-form-item label="饭量">
             <el-col :span="8">
            <el-input v-model="petInformation.appetite"/>
             </el-col>3~5斤
         </el-form-item>

         <el-form-item label="心率">
             <el-col :span="8">
            <el-input v-model="petInformation.heartRate"/>
             </el-col>88~105
         </el-form-item>

         <el-form-item label="大便次数">
             <el-col :span="8">
            <el-input v-model="petInformation.defecationTimes"/>
             </el-col>3~5
         </el-form-item>

         <el-form-item label="血压">
             <el-col :span="8">
            <el-input v-model="petInformation.bloodPressure"/>
             </el-col>160~188
         </el-form-item>

         <el-form-item label="体检结果">
         <el-col :span="8">
         <el-input v-model="petInformation.proposal"/>
         </el-col>
   </el-form-item>

   <el-form-item v-if="false" label="用户账号">
         <el-col :span="8">
         <el-input v-if="false" :disabled="true" v-model="petInformation.userName"/>
         </el-col>
   </el-form-item>

         <el-form-item>
            <el-button type="primary" @click="save">保存</el-button>
         </el-form-item>
      </el-form>
  </div>
</template>

<script>
import petInformation from '@/api/petInformation'
import reserve from '@/api/reserve'
export default {
  data() {
      return {
         petInformation:{},//petInformation对象
        
      }
   },
   created() {//页面渲染之前执行
      //获取路由userId值
      if(this.$route.params && this.$route.params.userId) {
         const userName = this.$route.params.userId
         this.petInformation.userName = userName
         const petType = this.$route.params.petType
         this.petInformation.petType = petType
      } else {
         //表单数据清空
         this.petInformation = {}
      }
   },
   methods: {
      //锁定和取消锁定
      lockReserve(id,status) {
         reserve.lockReserve(id,status)
            .then(response => {
               //刷新
            })
      },
      //根据id查询
      getPetInformation(id) {
         petInformation.getPetInformation(id) 
            .then(response => {
               this.petInformation = response.data
            })
      },
      //添加
      save() {
         petInformation.savePetInformation(this.petInformation)
            .then(response => {
               //提示
               this.$message({
                  type: 'success',
                  message: '添加成功!'
               })
               //跳转列表页面，使用路由跳转方式实现
               this.$router.push({path:'/petInformation/list'})
            })
      },
      //修改
      update() {
         petInformation.updatePetInformation(this.petInformation)
            .then(response => {
               //提示
               this.$message({
                  type: 'success',
                  message: '修改成功!'
               })
               //跳转列表页面，使用路由跳转方式实现
               this.$router.push({path:'/petInformation/list'})
            })
      },
      saveOrUpdate() {
         //判断添加还是修改
         if(!this.petInformation.userName) { //没有id，做添加
            this.save();
         }else {//修改
            this.update()
         }
      }
   }

}
</script>

<style>
#style22{
background:url(../../images/2.jpg);
width:100%; 
height:100%;  
position:absolute;
background-size:100% 100%;}
</style>